'use strict'

module.exports = (app) => {
  const { STRING, INTEGER } = app.Sequelize

  const TestTest = app.model.define(
    'test_test',
    {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      test_id: {
        type: STRING,
        primaryKey: true,
        allowNull: false,
        unique: true
      },
      test_name: {
        type: STRING
      },
      remark: {
        type: STRING
      }
    },
    {
      // timestamps: false, // 不使用createAt和updateAt字段
      freezeTableName: true, // 禁止自动复数化表名
      createdAt: 'created_at',
      updatedAt: 'updated_at'
    }
  )

  // 联表查询
  TestTest.associate = function () {
    TestTest.belongsTo(app.model.TestTestforeign, {
      foreignKey: 'test_id',
      targetKey: 'testforeign_id',
      as: 'test_detail'
    })
  }

  return TestTest
}
